package com.yang.action;

import com.yang.entity.Order;
import com.yang.service.OrderService;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/OrderQueryById")
public class OrderQueryByIdAction extends HttpServlet {
    OrderService orderService = new OrderService();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        Order obj = orderService.queryOrderById(id);
        resp.setContentType("text/json;charset=utf-8");
        PrintWriter out = resp.getWriter();
        Gson g = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
        out.write(g.toJson(obj));
        out.flush();
        out.close();
    }
}

